package com.szxy.miaosha.service.impl;

import com.szxy.miaosha.dao.MiaoshaOrderDao;
import com.szxy.miaosha.domain.Goods;
import com.szxy.miaosha.domain.MiaoshaOrder;
import com.szxy.miaosha.exception.GlobalException;
import com.szxy.miaosha.service.MiaoshaOrderService;
import com.szxy.miaosha.vo.GoodsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Author: zwz
 * @Date:2020/9/8 23:51
 * @Description:com.szxy.miaosha.service.impl
 * @Version:1.0
 **/
@Service
public class MiaoshaOrderServiceImpl implements MiaoshaOrderService {

    @Autowired
    private MiaoshaOrderDao miaoshaOrderDao;

    @Override
    public MiaoshaOrder getMiaoShaOrderByUserIdAndGoodsId(Long userId, Long GoodsId) {
        return miaoshaOrderDao.getMiaoShaOrderByUserIdAndGoodsId(userId, GoodsId);
    }

    @Override
    @Transactional(rollbackFor = GlobalException.class)
    public void insertOrder(GoodsVo goodsVo, Long userId, Long orderId) {
        MiaoshaOrder miaoshaOrder = new MiaoshaOrder();
        miaoshaOrder.setGoodsId(goodsVo.getId());
        miaoshaOrder.setUserId(userId);
        miaoshaOrder.setOrderId(orderId);
        miaoshaOrderDao.insertOrder(miaoshaOrder);
    }
}
